# PROTOTYPE, NOT TEST-COVERED!

def greater_common_part ( entries ) :
    part = ''
    if len ( entries ) > 0 :
        min_len = min ( [ len ( s ) for s in entries ] )
        for index in xrange ( min_len ) :
            current_part = part
            for entry in entries :
                if current_part == part :
                    current_part += entry [ index ]
                elif not entry . startswith ( current_part ) :
                    return part
            part = current_part
    return part

class knowledge_base :
    def __init__ ( self , mediator ) :
        self . _all_entries = set ( )
        self . _mediator = mediator
    def store_kb_type ( self , s ) :
        self . _all_entries . add ( s )
        self . _mediator . new_kb_type_added ( s )
        self . _mediator . set_greater_common_kb_types_part ( greater_common_part ( self . _all_entries ) )
    def request_is_kb_type_stored ( self , kb_type ) :
        self . _mediator . receive_is_kb_type_stored ( kb_type in self . _all_entries )
    def request_kb_types_starting_with ( self , prefix ) :
        entries_found = [ ]
        for entry in self . _all_entries :
            if entry . startswith ( prefix ) :
                entries_found += [ entry ]
        self . _mediator . receive_kb_types_starting_with ( entries_found )
